//201902104047 周润恺
package cn.edu.sdjzu.xg.bysj.service;


import cn.edu.sdjzu.xg.bysj.dao.DegreeDao;
import cn.edu.sdjzu.xg.bysj.domain.Degree;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;

//提供业务方案
public final class DegreeService {
    //获得degreeDao实例
    private static DegreeDao degreeDao
            = DegreeDao.getInstance();
    //新建degreeService对象
    private static DegreeService degreeService
            =new DegreeService();
    private DegreeService(){}
    //获得degreeService实例
    public static DegreeService getInstance(){
        return degreeService;
    }
    //查找所有学位信息
    public Collection<Degree> findAll(Collection<Condition> condition, Pagination pagination) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Collection<Degree> degrees = degreeDao.findAll(connection,condition,pagination);
        JdbcHelper.close(connection);
        return degrees;
    }
    //根据id查找学位信息
    public Degree find(Integer id) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Degree degree = degreeDao.find(connection,id);
        JdbcHelper.close(connection);
        return degree;
    }
    //更新学位信息
    public boolean update(Degree degree) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean updated = degreeDao.update(connection,degree);
        JdbcHelper.close(connection);
        return updated;
    }
    //添加学位
    public boolean add(Degree degree) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean added = degreeDao.add(connection,degree);
        JdbcHelper.close(connection);
        return added;                                                                                     
    }
    //删除学位
    public boolean delete(Integer id) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean deleted = degreeDao.delete(connection,id);
        JdbcHelper.close(connection);
        return deleted;
    }
}

